package com.youlian.cloud.core.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 * 公共的MVC层的解析器定义
 *
 * @author : liukx
 * @create : 2018/6/4 16:47
 * @email : liukx@elab-plus.com
 */
@Configuration
public class SpringMvcConfig {


    @Autowired
    private Environment env;

    /**
     * 构建一个文件上传解析器
     *
     * @return
     */
    @Bean(name = "multipartResolver")
    public MultipartResolver getCommonsMultipartResolver() {
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        multipartResolver.setMaxUploadSize(Long.valueOf(env.getProperty("mvc.multipartResolver.MaxUploadSize", "10485760")));
        multipartResolver.setDefaultEncoding("UTF-8");
        return multipartResolver;
    }

}
